package represent.expression;

import java.util.Collection;

import metadata.schema.Schema;


import represent.Scan;
import represent.type.Type;



/**
 * The interface corresponding to SQL expressions.
 * @author Edward Sciore
 *
 */
public abstract class Expression {

	protected String alias;
	
	/**
	 * Returns true if the expression is a constant.
	 * @return true if the expression is a constant
	 */
	public abstract boolean  isConstant();

	/**
	 * Returns true if the expression is a field reference.
	 * @return true if the expression denotes a field
	 */
	public abstract boolean  isFieldName();

	/**
	 * Returns the constant corresponding to a constant expression.
	 * Throws an exception if the expression does not
	 * denote a constant.
	 * @return the expression as a constant
	 */
	public abstract Type asConstant();

	/**
	 * Returns the field name corresponding to a constant expression.
	 * Throws an exception if the expression does not
	 * denote a field.
	 * @return the expression as a field name
	 */
	public abstract String   asFieldName();

	/**
	 * Evaluates the expression with respect to the
	 * current record of the specified scan.
	 * @param s the scan
	 * @return the value of the expression, as a Constant
	 */
	public abstract Type evaluate(Scan s);

	/**
	 * get the value of the expression with respect to 
	 * the current record of the specified scan
	 * @param s
	 * @return
	 */
	public abstract Type getVal(Scan s);

	/**
	 * Get the name/alias of the expression, to be used when construct new schema
	 * @return the name of expression referred
	 */
	public abstract String getReferName();

	/**
	 * Determines if all of the fields mentioned in this expression
	 * are contained in the specified schema.
	 * @param sch the schema
	 * @return true if all fields in the expression are in the schema
	 */
	public abstract boolean  appliesTo(Schema sch);

	/**
	 * get the full type of the expression, to be used when construct new schema
	 * @param sch
	 * @return string of the type
	 */
	public abstract int getType(Schema sch);

	/**
	 * Get the name used within the current query
	 * @return the name within current query
	 */
	public abstract String getFieldName();

	/**
	 * get all the field names mentioned in the expression
	 * @return a collection of field name
	 */
	public abstract Collection<String> getNeededFields();

	public abstract void addTableName(Schema schema);

	public void setAlias(String alias){
		this.alias = alias;
	}





}